package com.n5x.service.impl;

import com.n5x.mapper.promotion.PromotionMapper;
import com.n5x.model.promotion.Promotion;
import com.n5x.service.IPromotionService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/9/22.
 */
@Service
@Transactional
public class IPromotionServiceImpl implements IPromotionService {
    @Autowired
    private PromotionMapper promotionMapper;

    public Promotion save(Promotion promotion) {
        Assert.notNull(promotion,"promotion不能为空");
        if (StringUtils.isNotBlank(promotion.getId())) {
            promotionMapper.update(promotion);
        } else {
            promotion.setCreateTime(new Date());
            promotionMapper.insert(promotion);
        }
        return promotion;
    }

    public List<Promotion> findAll(Map<String, Object> params) {
        return promotionMapper.find(params);
    }

    public Promotion get(String id) {
        Assert.notNull(id,"id不能为空");
        return promotionMapper.get(id);
    }
}
